﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace FusionDotNet
{
    /// <summary>
    /// List the tables visible to the current Google Fusion account.
    /// </summary>
    public class ListTablesCommand : GetCommand<ListTablesResult>
    {
        private const string COMMAND = "SHOW TABLES";

        /// <summary>
        /// Sets the Query string to 'SHOW TABLES'
        /// </summary>
        /// <returns>String to use as the Query string.</returns>
        protected override string GetCommandQueryString()
        {
            return COMMAND;
        }

        internal override ListTablesResult CreateResult(StreamReader reader)
        {
            ListTablesResult result = new ListTablesResult();
            string[] headers = reader.ReadLine().Split(',');
            while (!reader.EndOfStream)
            {
                string[] tableInfo = reader.ReadLine().Split(',');
                int tableId = Int32.Parse(tableInfo[0]);
                result.AddTable(tableId, tableInfo[1]);
            }
            return result;
        }

    }
}
